package com.qhy.controller;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qhy.pojo.TbQuestion;
import com.qhy.service.IQuestionService;

@RequestMapping("problem")
@Controller
public class QuestionController {
	
	@Resource
	private IQuestionService service;
	
	
	@RequestMapping("queryAll.do")
	public String queryAll(@RequestParam(defaultValue = "1") Integer tr,HttpServletRequest request) {
		request.getSession().setAttribute("f_question", service.query0());
		PageHelper.startPage(tr, 8);
		PageInfo<TbQuestion> page = new PageInfo<TbQuestion>(service.queryAll());
		request.setAttribute("p", page);
		return "question";
	}
	
	@RequestMapping("deletequestion.do")
	public String deletequestion(Integer questionId) {
		int row = service.deletequestion(questionId);
		return "forward:/problem/queryAll.do";
	}
	
	
	@RequestMapping("addQuestion.do")
	public String addQuestion(TbQuestion question) {
		int row = service.addQuestion(question);
		return "forward:/problem/queryAll.do";
	}
	
	@RequestMapping("findById.do")
	public String findById(HttpServletRequest request,Integer questionId) {
		request.setAttribute("update_question", service.findById(questionId));
		return "update_question";
	}
	
	
	@RequestMapping("updateQuestion.do")
	public String updateQuestion(TbQuestion question) {
		int row = service.updateQuestion(question);
		return "forward:/problem/queryAll.do";
	}
	
	
	
	
	
	
}
